package com.softer.chengxin.home.service.impl;

import com.softer.chengxin.common.domin.JsonResult;
import com.softer.chengxin.common.domin.ManagerPageResult;
import com.softer.chengxin.home.dao.MessageDao;
import com.softer.chengxin.home.domin.Message;
import com.softer.chengxin.home.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Gong Zhiyang
 * @date 2018/9/26
 */
@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;

    /**
     * 通过企业id查询该企业的message条数
     *
     * @param page  第几页
     * @param limit 查几条
     * @param id    企业id
     * @return 结果集
     */
    @Override
    public ManagerPageResult getMessageList(int page, int limit, Integer id) {
        try {
            ManagerPageResult managerPageResult = new ManagerPageResult();
            JsonResult jsonResult = new JsonResult();
            managerPageResult.setCount(messageDao.getMessageCount(String.valueOf(id)));
            List<Message> list = messageDao.getMessageByCropId(String.valueOf(id), (page - 1) * limit, limit);
            jsonResult.setDs(list);
            managerPageResult.setJson(jsonResult);
            return managerPageResult;
        } catch (Exception e) {
            return new ManagerPageResult();
        }
    }
}